<script setup>
  import api from "./api.js";
  import ApplyApproveBody from "./body.vue";
  import useTodoStore from "@/store/modules/todo.js";
  const todoStore = useTodoStore();

  const emit = defineEmits(['sub']);

  const openFlag = ref(false);
  const taskId = ref();

  const body = ref();
  const detailInfo = ref({});
  const todoData = reactive({
    remark: null
  });
  provide('detailInfo', detailInfo);
  provide('todoData', todoData);

  function open(row) {
    openFlag.value = true;
    taskId.value = row.task.id;
    const apply = row.apply;

    api.detail(apply).then(response=> {

      detailInfo.value = response;

      // todoStore.setTodoData(response);
    })
  }

  function close() {
    openFlag.value = false;
  }

  function reject() {

    api.reject({
      taskId: taskId.value,
      remark: todoData.remark
    }).then(()=> {
      emit('sub');
      close()
    })
  }

  function approve() {
    api.approve({
      taskId: taskId.value,
      remark: todoData.remark
    }).then(()=> {
      emit('sub');
      close()
    })
  }

  defineExpose({
    open
  })

</script>

<template>
  <div>
    <!-- 添加或修改资产清单表对话框 -->
    <el-dialog ref="editDialog" v-model="openFlag" title="待办" width="50%" append-to-body>
      <ApplyApproveBody ref="body"></ApplyApproveBody>

      <div slot="footer" class="dialog-footer">
        <el-row type="flex" justify="end">
          <el-button type="danger" @click="reject">驳回</el-button>
          <el-button type="primary" @click="approve">同意</el-button>
        </el-row>
      </div>

    </el-dialog>
  </div>
</template>

<style scoped lang="scss">

</style>